package com.thinkingstar.iads.projectcenter.serviceImpl;

import com.thinkingstar.iads.datacenter.entity.*;
import com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao;
import com.thinkingstar.iads.datacenter.entity.dao.*;
import com.thinkingstar.iads.projectcenter.entity.PcProjectConstantData;
import com.thinkingstar.iads.projectcenter.entity.PcProjectInfo;
import com.thinkingstar.iads.projectcenter.entity.PcSjpsFile;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectConstantData;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectData;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcSjpsFile;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.QueryResult;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectSjpsData;
import org.nutz.lang.util.NutMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ProjectDcsjServiceImpl
 * @Description: 动车设计维护
 * @author z
 * @date  
 */
@IocBean
public class ProjectSjpsServiceImpl {

	@Inject
	private DaoPcProjectData daoPcProjectData;

	@Inject
	private DaoTemplateVersion daoTemplateVersion;

	@Inject
	private DaoPcProjectConstantData daoPcProjectConstantData;

	@Inject
	private DaoDcProjectMention daoDcProjectMention;

	@Inject
	private DaoDcProjectDesignCell daoDcProjectDesignCell;

	@Inject
	private DaoDcCompoundTemplate daoDcCompoundTemplate;

	@Inject
	private DaoPcSjpsFile daoPcSjpsFile;

	@Inject
	private DaoPcProjectSjpsData daoPcProjectSjpsData;

	@Inject CommonDao commonDao;

	@Inject
	private DaoDcTemplateVariable daoDcTemplateVariable;


	public List<Map> getDcTemplateVersionList(NutMap param) {
		PcProjectInfo project_info = daoPcProjectData.fetch((String)param.get("project_id"));
		String phase_id = project_info.getProject_design_phase_id();
		String content_id = project_info.getProject_design_content_id();
		return daoPcProjectSjpsData.getDcTemplateVersionList(content_id,phase_id);
	}

	public List<NutMap> getMentionFjghByPhaseAndContentId(NutMap param) {
		PcProjectInfo project_info = daoPcProjectData.fetch((String)param.get("project_id"));
		String phase_id = project_info.getProject_design_phase_id();
		String content_id = project_info.getProject_design_content_id();
		return daoDcProjectMention.getMentionFjghByPhaseAndContentId(phase_id,content_id);
	}

	public List<NutMap> getMentionJghByPhaseAndContentId(NutMap param) {
		PcProjectInfo project_info = daoPcProjectData.fetch((String)param.get("project_id"));
		String phase_id = project_info.getProject_design_phase_id();
		String content_id = project_info.getProject_design_content_id();
		return daoDcProjectMention.getMentionJghByPhaseAndContentId(phase_id,content_id);
	}

	public QueryResult findSjpsTemplateList(NutMap param) {
		PcProjectInfo project_info = daoPcProjectData.fetch((String)param.get("project_id"));
		String phase_id = project_info.getProject_design_phase_id();
		String content_id = project_info.getProject_design_content_id();
		param.put("phase_id",phase_id);
		param.put("content_id",content_id);
		return daoPcProjectSjpsData.findDesignTemplate(param);
	}

	public DcTemplateVersion getDcTemplateVersionById(String id) {
		return daoTemplateVersion.fetch(id);
	}

	public List<PcProjectConstantData> getConstantData(String project_id) {
		return daoPcProjectConstantData.getPcProjectConstantDataList(project_id);
	}

	public List<DcProjectMentionInformation> getMentionDataListByIds(String mention_ids) {
		String[] ids = mention_ids.split(",");
		List<DcProjectMentionInformation> list = new ArrayList<>();
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				list.add( daoDcProjectMention.fetch(ids[i]));
			}
		}
		return list;
	}
	public String getMentionDataByIds(String mention_ids) {
		String[] ids = mention_ids.split(",");
		String mention_data = "";
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				DcProjectMentionInformation mentionData = daoDcProjectMention.fetch(ids[i]);
				mention_data+=mentionData.getMention_information_name()+"、";
			}
		}
		return mention_data;
	}

	public List<DcProjectDesignCell> getDesignCellListByIds(String design_cell_ids){
		String[] ids = design_cell_ids.split(",");
		List<DcProjectDesignCell> list = new ArrayList<>();
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				list.add( daoDcProjectDesignCell.fetch(ids[i]));
			}
		}
		return list;
	}

	public String getDesignCellByIds(String design_cell_ids) {
		String[] ids = design_cell_ids.split(",");
		String design_cell_data = "";
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				DcProjectDesignCell designCell = daoDcProjectDesignCell.fetch(ids[i]);
				design_cell_data+=designCell.getDesign_cell_table_name()+"、";
			}
		}
		return design_cell_data;
	}

	public List<DcCompoundTemplate> getTemplateListByIds(String template_ids){
		String[] ids = template_ids.split(",");
		List<DcCompoundTemplate> list = new ArrayList<>();
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				list.add( daoDcCompoundTemplate.fetch(ids[i]));
			}
		}
		return list;
	}

	public String getTemplateByIds(String template_ids) {
		String[] ids = template_ids.split(",");
		String template_data = "";
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				DcCompoundTemplate template = daoDcCompoundTemplate.fetch(ids[i]);
				template_data+=template.getTemplate_name()+"、";
			}
		}
		return template_data;
	}


	public PcSjpsFile getPcSjpsFile(String project_id,String fileNum){
		PcSjpsFile sjpsFile = daoPcSjpsFile.findByProjectAndFileNum(project_id,fileNum);
		return sjpsFile;
	}

	public void insertOrUpdatePcSjpsFile(String project_id,String sorting,String fileNum) {
		PcSjpsFile sjpsFile = daoPcSjpsFile.findByProjectAndFileNum(project_id,fileNum);
		if (null!=sjpsFile){
			sjpsFile.setSorting(sorting);
			daoPcSjpsFile.update(sjpsFile);
		} else {
			sjpsFile = new PcSjpsFile();
			sjpsFile.setSorting(sorting);
			sjpsFile.setProject_id(project_id);
			sjpsFile.setFileNum(fileNum);
			PcProjectInfo project_info = daoPcProjectData.fetch(project_id);
			sjpsFile.setProjectName(project_info.getProject_name());
			daoPcSjpsFile.insert(sjpsFile);
		}
	}

	public List<DcTemplateVariable> getTemplateVariable(String template_id) {
		return daoDcTemplateVariable.getTemplateVariable(template_id);
	}

	public Map<String,String> getVariableValues(List<DcTemplateVariable> list, String project_id) {
		return daoDcTemplateVariable.getVariableValues(list,project_id);
	}
}
